package encrypt;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;

public class MD5 {
	private static MessageDigest md;
	
	public static String encrypt(String srcData) {
		StringBuilder encData = new StringBuilder();
		Formatter formatter = new Formatter(encData);
		
		try {
			md = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		
		byte[] bytData = srcData.getBytes();
		md.update(bytData);
		byte[] digest = md.digest();
		for(int i = 0; i < digest.length; i++) {
			formatter.format("%02x", digest[i]);
		}
		
		formatter.close();
		
		return encData.toString();
	}
}
	
	
